﻿@page
@model ToolGood.FlowVision.Pages.Members.Projects.EditModel
@{
	Layout = "~/Pages/Shared/_Layout_Edit.cshtml";
}
@section css{
	<style>
		.layui-table td, .layui-table th { padding: 3px; }
		.layui-form-item .layui-form-checkbox[lay-skin=primary] { margin-top: 5px; margin-bottom: 5px; }
	</style>
}
<div style="overflow-x:hidden;background-color:#f3f3f4;height: 100%;">
	<form id="edit-form" style="height: 100%;">
		<input type="hidden" name="id" value="@Model.Dto.Id" />
		@Html.AntiForgeryToken()
		<div class="layui-form layui-form-sm" lay-filter="form" style="padding: 20px 30px 0 0;">
			<div class="layui-form-item-sm">
				<label class="layui-form-label-sm">CODE<span class="red"> *</span></label>
				<div class="layui-input-block-sm">
					<input type="text" class=" layui-input layui-input-sm" id="txt_Code" name="Code" value="@Model.Dto.Code" autocomplete="off">
				</div>
			</div>
			<div class="layui-form-item-sm">
				<label class="layui-form-label-sm">项目名称<span class="red"> *</span></label>
				<div class="layui-input-block-sm">
					<input type="text" class="layui-input layui-input-sm" id="txt_name" name="name" value="@Model.Dto.Name" autocomplete="off">
				</div>
			</div>
			<div class="layui-form-item-sm">
				<label class="layui-form-label-sm">索引</label>
				<div class="layui-input-block-sm">
					<input type="checkbox" name="ExcelIndex" lay-skin="primary" value="0" lay-filter="checkType" title="正常索引，从0开始" @((Model.Dto.ExcelIndex==0).ToChecked()) />
					<input type="checkbox" name="ExcelIndex" lay-skin="primary" value="1" lay-filter="checkType" title="使用Excel索引，从1开始" @((Model.Dto.ExcelIndex==1).ToChecked()) />
				</div>
			</div>
			<div class="layui-form-item-sm">
				<label class="layui-form-label-sm">数量</label>
				<div class="layui-input-block-sm">
					<input type="checkbox" name="NumberRequired" lay-skin="primary" value="1" lay-filter="checkType" title="数量必填" @((Model.Dto.NumberRequired==1).ToChecked()) />
					<input type="checkbox" name="NumberRequired" lay-skin="primary" value="0" lay-filter="checkType" title="数量可空，默认为0" @((Model.Dto.NumberRequired==0).ToChecked()) />
				</div>
			</div>
			<div class="layui-form-item-sm">
				<label class="layui-form-label-sm">长度单位</label>
				<div class="layui-input-block-sm">
					<input type="checkbox" name="Distance" lay-skin="primary" value="5" lay-filter="checkType" title="KM" @((Model.Dto.Distance==5).ToChecked()) />
					<input type="checkbox" name="Distance" lay-skin="primary" value="4" lay-filter="checkType" title="M" @((Model.Dto.Distance==4).ToChecked()) />
					<input type="checkbox" name="Distance" lay-skin="primary" value="3" lay-filter="checkType" title="DM" @((Model.Dto.Distance==3).ToChecked()) />
					<input type="checkbox" name="Distance" lay-skin="primary" value="2" lay-filter="checkType" title="CM" @((Model.Dto.Distance==2).ToChecked()) />
					<input type="checkbox" name="Distance" lay-skin="primary" value="1" lay-filter="checkType" title="MM" @((Model.Dto.Distance==1).ToChecked()) />
				</div>
			</div>
			<div class="layui-form-item-sm">
				<label class="layui-form-label-sm">平方单位</label>
				<div class="layui-input-block-sm">
					<input type="checkbox" name="Area" lay-skin="primary" value="15" lay-filter="checkType" title="KM²" @((Model.Dto.Area==15).ToChecked()) />
					<input type="checkbox" name="Area" lay-skin="primary" value="14" lay-filter="checkType" title="M²" @((Model.Dto.Area==14).ToChecked()) />
					<input type="checkbox" name="Area" lay-skin="primary" value="13" lay-filter="checkType" title="DM²" @((Model.Dto.Area==13).ToChecked()) />
					<input type="checkbox" name="Area" lay-skin="primary" value="12" lay-filter="checkType" title="CM²" @((Model.Dto.Area==12).ToChecked()) />
					<input type="checkbox" name="Area" lay-skin="primary" value="11" lay-filter="checkType" title="MM²" @((Model.Dto.Area==11).ToChecked()) />
				</div>
			</div>
			<div class="layui-form-item-sm">
				<label class="layui-form-label-sm">立方单位</label>
				<div class="layui-input-block-sm">
					<input type="checkbox" name="Volume" lay-skin="primary" value="25" lay-filter="checkType" title="KM³" @((Model.Dto.Volume==25).ToChecked()) />
					<input type="checkbox" name="Volume" lay-skin="primary" value="24" lay-filter="checkType" title="M³" @((Model.Dto.Volume==24).ToChecked()) />
					<input type="checkbox" name="Volume" lay-skin="primary" value="23" lay-filter="checkType" title="DM³" @((Model.Dto.Volume==23).ToChecked()) />
					<input type="checkbox" name="Volume" lay-skin="primary" value="22" lay-filter="checkType" title="CM³" @((Model.Dto.Volume==22).ToChecked()) />
					<input type="checkbox" name="Volume" lay-skin="primary" value="21" lay-filter="checkType" title="MM³" @((Model.Dto.Volume==21).ToChecked()) />
				</div>
			</div>
			<div class="layui-form-item-sm">
				<label class="layui-form-label-sm">重量单位</label>
				<div class="layui-input-block-sm">
					<input type="checkbox" name="Mass" lay-skin="primary" value="33" lay-filter="checkType" title="T" @((Model.Dto.Mass==33).ToChecked()) />
					<input type="checkbox" name="Mass" lay-skin="primary" value="32" lay-filter="checkType" title="KG" @((Model.Dto.Mass==32).ToChecked()) />
					<input type="checkbox" name="Mass" lay-skin="primary" value="31" lay-filter="checkType" title="K" @((Model.Dto.Mass==31).ToChecked()) />
				</div>
			</div>

			<div class="layui-form-item-sm">
				<label class="layui-form-label-sm">备注</label>
				<div class="layui-input-block-sm">
					<textarea class="layui-textarea layui-textarea-sm" id="txt_Comment" name="Comment">@(Model.Dto.Comment.ToHtml())</textarea>
				</div>
			</div>

			<div class="layui-form-item-sm" style="text-align:center;padding-left: 30px;">
				<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="save(this);"> &nbsp;&nbsp; 提 交 &nbsp;&nbsp; </button>
				<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" onclick="closeWindow();"> &nbsp;&nbsp; 关 闭 &nbsp;&nbsp; </button>
			</div>
		</div>
	</form>
</div>
@section js{
	<script>
		layui.use(['element', 'form'], function () {
			var form = layui.form;
			form.on('checkbox(checkType)', function (data) {
				var name = $(this).attr("name")
				$("input[name='" + name + "']").prop("checked", false);
				$(this).prop("checked", true);
				form.render('checkbox');
			});
			form.render('checkbox');
		});
	</script>
	<script>
		function save(obj) {
			if ($("#txt_name").val().length < 2) { layer.alert("请输入项目名称"); $("#txt_name").focus(); return; }
			if ($("#txt_Code").val().length < 2) { layer.alert("请输入编码"); $("#txt_Code").focus(); return; }

			$(obj).prop("disabled", true);
			var url = "./Ajax/EditItem";
			var data = {
				data: $("#edit-form").serializeJson(),
				fingerprint: window.fingerprint
			}
			$.ajax({
				type: "POST",
				url: url,
				contentType: "application/json;charset=UTF-8",
				data: JSON.stringify(data),
				headers: { __RequestVerificationToken: data.data["__RequestVerificationToken"] },
				dataType: "JSON",
				success: function (data, textStatus, jqXHR) {
					if (data.state == "SUCCESS") {
						closeWindowAndReload();
					} else {
						$(obj).prop("disabled", false);
						if (data.message) {
							layer.msg(data.message);
						} else {
							layer.msg("出错了");
						}
					}
				},
				error: function (data, textStatus, errorThrown) { $(obj).prop("disabled", false); layer.msg("出错了"); }
			});


		}
	</script>
}
